package pl.com.like.sequoia.jms.client.producer;

import java.util.List;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.ObjectMessage;
import javax.jms.Session;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;

import pl.com.sequoia.jms.PdbCompareMessage;

public class JmsCompareMessageProducer implements IJmsCompareMessageProducer {

	private final static Logger log = LoggerFactory.getLogger(JmsCompareMessageProducer.class);

	private JmsTemplate template;

	public void compareObjects(final String parent, final List<String> compareTo) {

		template.send(new MessageCreator() {

			public Message createMessage(Session session) throws JMSException {
				PdbCompareMessage pdbMessage = new PdbCompareMessage(parent, compareTo);
				log.info("creating new pdbCompareMessage with parent {}, and compare objects {}", new Object[] {
						parent, compareTo });
				ObjectMessage objMessage = session.createObjectMessage(pdbMessage);
				return objMessage;
			}
		});
	}

	public JmsTemplate getTemplate() {
		return template;
	}

	public void setTemplate(JmsTemplate template) {
		this.template = template;
	}

}
